package com.zretc.service.impl;

import com.zretc.dao.VipTypeMapper;
import com.zretc.entity.Vip;
import com.zretc.entity.VipType;
import com.zretc.service.BackVipOrdersService;
import com.zretc.service.BackVipTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class BackVipTypeServiceImpl implements BackVipTypeService {


    @Autowired
    VipTypeMapper vipTypeMapper;

    @Override
    public Float findDiscountById(Integer accountId) {

        VipType vipType = new VipType();
        BigDecimal discount = null;
        Vip vip = vipTypeMapper.findEndTimeByaccountId(accountId);

        //判断会员是否过期
         if(vip != null){

             //未过期返回折扣
             vipType = vipTypeMapper.findDiscountById(accountId);
             discount = vipType.getVipDiscount();

         }else{

             //过期返回1
             discount = new BigDecimal("1");
             vipType.setVipDiscount(discount);

         }
         return discount.floatValue();
    }
}



